<?php
class Block_BlkCategory extends Zend_View_Helper_Abstract{
	
	private $_filter;
	
	public function blkCategory(){
		$db = Zend_Db_Table::getDefaultAdapter();
		$select = $db->select()->from('category',array('id','name','parent'))
								->where('status = 1')
								->where('parent = 0')
								->order('order ASC');
		//echo '</br>' . $select;
	
		$filter = new Zend_Filter();
		$filter->addFilter(new Zend_Filter_StringToLower(array('encoding'=>'utf-8')))
				->addFilter(new Zendvn_Filter_Remove())
				->addFilter(new Zend_Filter_Alnum(true))
				->addFilter(new Zend_Filter_PregReplace('#\s+#','-'));
		$this->_filter = $filter;
		
		$result = $db->fetchAll($select);
		
		$newMenu = '<ul class="serLink">';
		foreach ($result as $val){
			$select = $db->select()->from('category',array('id','name','parent'))
				->where('status = 1')
				->where('parent =' . $val['id'])
				->order('order ASC');
				$kq = $db->fetchAll($select);
			if(count($kq) == 0){
				$newMenu .= '<li><a href="#">'. $val['name'] .'</a>';
			}else{
				$newMenu .= '<li><a href="#">'. $val['name'] .'</a>';
				$newMenu .= '<ul>';
				foreach ($kq as $val2){
					$link = $this->view->url(array('module'=>'default','controller'=>'detail',
													'action'=>'category','cate_name'=>Zendvn_Filter_Remove::filterSEO($val['name']),'title'=>Zendvn_Filter_Remove::filterSEO($val2['name']),'cat_id'=>$val2['id']),'detail_cate',true);
					$newMenu .= '<li><a href="'.$link.'">-- ' . $val2['name'] . '</a>';
					$newMenu .= '</li>';
				}
				$newMenu .= '</ul>';
			}
			$newMenu .= '</li>';
		}
		$newMenu .= '</ul>';
		include 'BlkCategory_UI.php';
	}
	
}